require.config({
    baseUrl: './js',
    urlArg: 'v=1.0',
    paths: {        
        'jquery': 'vendor/jquery.min',      
        'jscrollpanel' : 'vendor/jquery.jscrollpane',
        'react': 'vendor/react-with-addons',          
        'react.backbone': 'vendor/react.backbone',   
        'backbone': 'vendor/backbone',
        'underscore': 'vendor/lodash.min',  
        'text': 'vendor/text',
        'json': 'vendor/json'           
    },
    shim: {
        'underscore': {
            exports: '_'
        },
        'jquery' : {
            exports: '$'
        },
        'jscrollpanel': ['jquery'],

    },        
    packages : ["PDFView", "Plugins/Form", "Plugins/Hand", "Plugins/Annot"]
});

require(['PDFViewer', 'utils'], function(PDFViewer, UCX_Utils) {
    var settings = {
        s3Key: UCX_Utils.getUrlParam("doc")
    };
    var pdfApi = $("#docViewer").pdfViewer(settings).data("jsp");
  

    pdfApi.curPageChanged(function(event, data) {          
        $("#pageIndexInputSelect").val(data.curIndex);
    });

 
    pdfApi.scaleChanged(function(event, data) {          
        $('.btnSelectZoom').val(data.scale);
    });


    pdfApi.pageCountChanged(function(event, data){
       var select = $("#pageIndexInputSelect").empty();         
       var option = $("<option>");
       var pageCount = data.pageCount;
       for (var index = 0; index < pageCount; index++) {
            select.append(option.clone().text(index + 1 + " / " + pageCount).attr('value', index));
       }          
    });
    
   //pdfApi.setScale({'scale': '0.5'});

    $('.btnSelectZoom').on('change', function() {
        pdfApi.setScale({
            'zoomMode': $(this).val()
        });
    });

    $('#btnGoToNextPage').on("click", function() {
        pdfApi.nextPage();
    });

    $('#btnGoToPreviousPage').on("click", function() {
        pdfApi.previousPage();
    });

    $('.fwr-goToPage-input').on('change', function() {
         pdfApi.gotoPage({
            'pageIndex': $(this).val()
        });
    });

    $('.btnHandTool').on('click', function() {
        pdfApi.setCurrentToolByName("handTool");
    });

    $("#btnTypewriter").on('click', function() {
         pdfApi.setCurrentToolByName("annotTool");
    });
});

